package config

import (
	"sync"
)

type NodeConfig struct {
	App struct {
		Host      string
		AccountId string
		Predict   struct {
			Port interface{}
		}
		Cs struct {
			MasterNamespace string
		}
		EnableOSSLog  bool
		OssLogSize    int
		OssLogBackups int
	}
	Oss struct {
		Type             string
		Endpoint         string
		InternalEndpoint string
		Bucket           string
		AccessKey        string
		AccessSecret     string
	}
}

var (
	nodeConfig *NodeConfig
	argsOnce   sync.Once
)

// because of Node config was inhired in system env, system env setting was binding to kubernetes pod
// so no need to update the config until pod restart
func GetArgs() *NodeConfig {
	argsOnce.Do(func() {
		nodeConfig = buildArgs()
	})

	return nodeConfig
}

func buildArgs() *NodeConfig {
	//e := GetEnv()
	//if e.NodeConfig == "" {
	//	logrus.Errorf("No node config found, check env")
	//	return nil
	//}
	//err := json.Unmarshal([]byte(e.NodeConfig), &nodeConfig)
	//if err != nil {
	//	logrus.Errorf("json unmarshal node config failed, %s", e.NodeConfig)
	//}
	nodeConfig = &NodeConfig{}

	return nodeConfig
}
